package org.flexlancer.utils
{
	public class DateTimeUtils
	{
		public static function Makedigits(num:int,digits:int=2):String{
			try{
				var count:int = 1;
				var tmpNum:int = num;
				var ret:String = num.toString();
				
				for ( count ; count < digits ; count ++ ){
					tmpNum /= 10;
					if ( tmpNum == 0 ){
						ret = "0" + ret;
					}
				}
				
				return ret;
			}catch(err:Error){
				throw err;
			}
			return "";
		}
		
		public static function ToStandardDate(dateObject:Date):String{
			try{
				return Makedigits(dateObject.fullYear) + "-" + Makedigits(dateObject.month + 1) +"-" + Makedigits(dateObject.date);
			}catch(err:Error){
				throw err;
			}
			return "";
		}

		public static function ToStandardTime(dateObject:Date):String{
			try{
				return Makedigits(dateObject.hours) + ":" + Makedigits(dateObject.minutes);
			}catch(err:Error){
				throw err;
			}
			return "";
		}
		
		public static function get TodayCutOffDate():Date{
			var dtNow:Date = new Date();
			
			if ( dtNow.hours < 6 ){
				dtNow.setTime(dtNow.getTime() - 24 * 60 * 60 * 1000 );
			}
			return  dtNow;			
		}
		
		public static function get TodayCutOffDateString():String{
			var dtNow:Date = new Date();
			
			if ( dtNow.hours < 6 ){
				dtNow.setTime(dtNow.getTime() - 24 * 60 * 60 * 1000 );
			}
			return  ToStandardDate(dtNow);			
		}
	}
}